<?php
/**
 * WrapItAllUp! The webdeveloper's insurance.
 *
 * The stand-alone insurance package.
 * Initialises itself.
 *
 * @author David van der Sluis <david@davidvandersluis.nl>
 * @version 0.1
 * @package WrapItAllUp
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 * @license http://creativecommons.org/licenses/by-sa/3.0/ CC BY SA 
 */

/**
 * $aCONFIG
 * 
 * This is the config array needed to use the class.
 */
$aCONFIG['key'] = 'test';

/**
 * WrapItAllUp! Class
 *
 * This is the class where the fireworks happen.
 *
 * @author David van der Sluis <david@davidvandersluis.nl>
 * @package WrapItAllUp
 */
class WIAU {
    private $UIKEY;
    private $UIACTION;
    private $CONFIG;

    /**
     * Initialise WIAU
     */
    public function  __construct($CONFIG) {

        $this->CONFIG = $CONFIG;
        
        /**
         * Check if WIAU is being called remotely.
         * Since contructors can't return anything, execute the rest only when true.
         */
        if($this->InitVars() === true){
            $this->Dispatch();
        }
    }

    /**
     * InitVar
     *
     * Checks GET variables for WIAU relevant components. If not existant get out of this class a.s.a.p.
     */
    private function InitVars(){
        if(!isset($_GET['WIAUKEY']) && trim($_GET['WIAUKEY']) != ''){
            return false;
        }elseif(!isset($_GET['WIAUACTION']) && trim($_GET['WIAUACTION']) != ''){
            return false;
        }
        
        $this->UIKEY = (string) trim($_GET['WIAUKEY']);
        $this->UIACTION = (string) trim($_GET['WIAUACTION']);
        return true;
    }

    /**
     * Dispatcher
     *
     * Validates given key and dispatches to valid action.
     */
    private function Dispatch(){
        $aValidActions = array(
                            'capabilities',
                            'cleanup',
                            'zipsource',
                         );

        if((string) $this->UIKEY !== (string) $this->CONFIG['key']) return false;

        if(in_array($this->UIACTION, $aValidActions)){
            call_user_method(ucfirst($this->UIACTION), $this);
        }

    }

    /**
     * Capabilities
     *
     * Tests the capabilities of the hostserver.
     */
    private function Capabilities (){
    }

    /**
     * Cleanup
     *
     * Cleans up this class and remove any references to it.
     */
    private function Cleanup (){
    }
}
new WIAU($aCONFIG);
?>
